<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">开门记录</block>
		</cu-custom>
		<view class="cu-bar bg-white solid-bottom margin-top">
			<view class="action">
				<text class="cuIcon-title text-orange "></text>开门记录
			</view>
		</view>

		<view v-for="item in times" class="cu-timeline">
			<view class="cu-time">{{item.date}}</view>
			<view class="cu-item">
				<view class="content">
					<view class="cu-capsule radius">
						<view class="cu-tag bg-cyan">{{item.AM}}</view>
						<view class="cu-tag line-cyan">{{item.time}}</view>
					</view>
					<view class="margin-top">
						<image @tap="ViewImage(item.url)" :src="$constant.IMG_VERSION == $constant.OSS?item.url:$constant.BASEURL+item.url" mode="aspectFill"></image>
					</view>
				</view>
			</view>
		</view>
		<no-more :show="!times.length>0" text="还没有开门记录哦"></no-more>
		<uni-load-more :status="status" :size="20" :content-text="contentText" />
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import {
		formateDate
	} from "@/common/utils.js"
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				times: [],
				page: 1,
				rows: 5,
				reload: false, //是否重新加载
				status: 'more',
				contentText: {
					// contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: ''
				}
			}
		},
		onLoad() {
			this.getRecordList()
		},
		onReachBottom() {
			if (this.status == 'noMore') return
			// this.status = 'more';
			this.status = 'loading';
			this.getRecordList()
		},
		methods: {
			ViewImage(url) {
				let urls = [url]
				uni.previewImage({
					urls: urls,
					current: 0
				});
			},
			getRecordList() {
				// var this
				uni.request({
					url: this.$constant.BASEURL + this.$constant.OPEN_DOOR_RECORD,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						username: getApp().globalData.username,
						token: getApp().globalData.token,
						uninto: getApp().globalData.orgcode,
						page: this.page,
						rows: this.rows
					},
					success: (res) => {
						let page = res.data.data
						// console.log(page)
						if (page.page * page.rows >= page.total) {
							this.status = 'noMore';
						}
						if (res.data.code == 0) {
							let list = page.results
							let times = []
							list.forEach(function(item){
								let time = formateDate(new Date(item.createDate.time),'Y-M-D h:min A')
								times.push({
									year:time.substring(0,4),
									date:time.substring(0,10),
									time:time.substring(11,16),
									AM:time.substring(17,19),
									url:item.url
								})
							})
							// console.log(times)
							this.times = this.reload ? times : this.times.concat(times)
							this.page++;
							this.reload = false;
							// console.log(list)
						} else {
							uni.showModal({
								content: res.data.message,
								showCancel: false
							})
						}
					}
				})
			},
		}
	}
</script>

<style>

</style>
